var toast = require("../../../components/toast/toast.js")
var common = require('../../../utils/util.js')
var app = getApp();
Page({
    data: {
        list: [],
        cancelHide: "hide",
        //订单处理成功或失败的按钮
        icon: '/image/icon-success.png',
        orderMessage: '支付成功',
        subMessage: ['订单正在处理，请您耐心等待'],
        //订单处理信息列表
        orderMessageArr: ['支付成功', '订单完成', '订单取消'],
        success: ['订单正在处理，请您耐心等待'],
        finish: ['已下单的用户请勿私下重复处理违章，否则因此导致的重复缴款损失将自行承担；异地差异罚款及产生滞纳金的罚单由客服通知补充；违章办理周期一般是2-5个工作日'],
        cancel: ['订单已撤销，如有疑问请联系客服', '客服电话：020-62936789'],
        //订单详细信息
        payAmount: 0,
        payTypeName: "微信支付",
        payNo: "",
        updateTime: "",
        orderId: ''
    },
    getOrderInfo: function (orderId) { 
        this.setData({"orderId": orderId})
        let _this = this;
        let param = {
            api: 'Service.UcOrder.OrderService.GetOrder',
            url: '/wx/carViola/getOrder.ajax',
            para: {
                "orderId": orderId  //'Test1726934550514'  
            }
        };

        app.requestSdkForNeedLogin({
            param: param,
            beforeSend: () => {
                //发送请求之前执行
                wx.showToast({
                    title: '请稍候',
                    icon: 'loading',
                    duration: 10000
                });
            },
            success: data => {
                if (data.code == 1000 && data.body.orderViolationList) {
                    let orderVoliationsList = data.body.orderViolationList;
                    let tsList = [];
                    for (let i = 0; i < orderVoliationsList.length; i++) {
                        let newLoation = "";
                        let location = orderVoliationsList[i].violationLocation;
                        let locationName = orderVoliationsList[i].locaitonName;
                        if (locationName == "") {
                            if (location.length > 5)
                                newLoation = location.substring(0, 5) + "...";
                            else
                                newLoation = location;
                        }
                        else
                            newLoation = locationName + "违章";
                        var tsItem = {
                            "carNumber": orderVoliationsList[i].carNumber,
                             "violationTime": app.toYMDDate(orderVoliationsList[i].violationTime), //orderVoliationsList[i].violationTime.substring(0, 10),
                            "fineAmount": orderVoliationsList[i].fineAmount,
                            "cooperPoundge": orderVoliationsList[i].cooperPoundge,
                            "pounDage": orderVoliationsList[i].pounDage,
                            "degree": orderVoliationsList[i].degree,
                            "other": orderVoliationsList[i].other,
                           // "canProcess": orderVoliationsList[i].canProcess,
                            "canProcessMsg": orderVoliationsList[i].canProcessMsg,
                            "locationName": newLoation.replace(null,'')
                        };
                        tsList.push(tsItem);
                    }
                    let orderStatus = data.body.orderStatus;
                    let completeTime = data.body.completeTime;
                    if (completeTime == null)
                        completeTime = "";

                    this.setData({
                        list: tsList,
                        payAmount: data.body.payAmount,
                        payTypeName: data.body.payTypeName,
                        payNo: data.body.chargeOrder.chargeSerialNum,
                        completeTime: app.toYMDHMSDate(completeTime),
                        completeTimeIsShow: completeTime?true:false,
                        completeText: orderStatus==4?'关闭时间':orderStatus==8?'完成时间':'',
                        payTime: app.toYMDHMSDate(data.body.chargeOrder.chargeTime),
                        statusName: data.body.statusName
                    });
                    //支付成功
                    if (orderStatus == 2) {
                        _this.setData({
                            icon: '/image/icon-success.png',
                            orderMessage: data.body.statusName,//_this.data.orderMessageArr[0],
                            subMessage: data.body.statusDesc   //_this.data.success
                        });
                    }
                    else if (orderStatus == 3||orderStatus == 4) {
                        //取消订单
                        _this.setData({
                            icon: '/image/icon-warning.png',
                            orderMessage: data.body.statusName,//_this.data.orderMessageArr[2],
                            subMessage: data.body.statusDesc,//_this.data.cancel,
                            cancelHide: "hide"
                        });
                    }
                    else if (orderStatus == 8) {
                        //订单完成
                        _this.setData({
                            icon: '/image/icon-success.png',
                            orderMessage: data.body.statusName,//_this.data.orderMessageArr[1],
                            subMessage: data.body.statusDesc,//_this.data.finish,
                            cancelHide: ""
                        });
                    }
                } else {
                    toast.show(this, data.msg)
                }
            },
            complete: data => {
                wx.hideToast();
            }
        });
    },
    onLoad: function (options) {
        let orderId = options.orderId;
        this.getOrderInfo(orderId)
    },
    onReady: function () {
        wx.setNavigationBarTitle({ title: "订单详情" })
    },
    onShow: function () {
        wx.setNavigationBarTitle({ title: "订单详情" })
    },
    onShareAppMessage: function () {
        return {
            title: '还在为违章处理排队烦恼吗？',
            desc: '车行易查违章，免费查询，实时提醒，快速在线缴罚款，车主最贴心的车务管家！ ',
            path: 'pages/carInfo/list/list'
        }
    }
})